
class dgParticle {
  float x;
  float y;
  float inc[];
  float way[];
  dgParticle() {}
  dgParticle(int windowW,int windowH) {
    int dif=1;
    this.x = windowW/2;
    this.y = windowH/2;
    if (random(10)>5.0) dif=1; else dif=-1;
    println(dif);
    this.inc = new float[]{0.5*dif+random(2),0.5*dif*-1+random(2),0};
    this.way = new float[]{random(1),random(1),0};
  }
  void createParticle(int windowW,int windowH) {
    int dif=1;
    this.x = windowW/2;
    this.y = windowH/2;
    if (random(10)>10) dif=1; else dif=-1;
    this.inc = new float[]{0.5*dif+random(0.5),0.5*dif+random(0.5),0};
    this.way = new float[]{random(1),random(1),0};
  }
  void drawIt(int windowW,int windowH) {
    fill(this.way[0]*255,255,this.way[1]*255);
    ellipseMode(CENTER);
    ellipse(this.x,this.y,windowW/40,windowH/40);
  }
  void moveIt(int windowW,int windowH) {
 //   if (noise(this.way[0]*this.way[1],this.x*this.y,this.inc[0]*this.inc[1])>0.5) this.way[0] += 0.2;
 //   else this.way[1] += 0.2;
 //   DogaMakeUnitVector(this.way);
 //   this.incX += this.way[0];
 //   this.incY += this.way[1];
    if ((this.x<1)&&(this.inc[0]<0)) {this.inc[0] *= -1;}
    if ((this.y<1)&&(this.inc[1]<0)) {this.inc[1] *= -1;}
    if ((this.x>windowW-1)&&(this.inc[0]>0)) {this.inc[0] *= -1;}
    if ((this.y>windowH-1)&&(this.inc[1]>0)) {this.inc[1] *= -1;}
    this.x += this.inc[0];// + this.way[0];
    this.y += this.inc[1];// + this.way[1];
  }
}

dgParticle[] myParticle;
int numOfParticles=3;
void setup () {
  int i=0;
  size(400,400);
  myParticle = new dgParticle[numOfParticles];
  for (i=0;i<numOfParticles;i++) myParticle[i] = new dgParticle(width,height);
}

void draw() {
  int i=0;
  background(0);
  for (i=0;i<numOfParticles;i++) {
    myParticle[i].moveIt(width,height);
    myParticle[i].drawIt(width,height);
  }
}
float DogaDotProduct(float V1[],float V2[]) {return V1[0]*V2[0]+V1[1]*V2[1]+V1[2]*V2[2];}
float DogaMakeUnitVector(float V[]) {
  float w=0;
  w = sqrt(DogaDotProduct(V,V));
  if (w!=0) {
    V[0] = V[0]/w;
    V[1] = V[1]/w;
    V[2] = V[2]/w;
  }
  else {
    V[0] = 0;
    V[1] = 0;
    V[2] = 0;
  }
  return w;
}
